package com.vic.mvc.framework.core;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.WebListener;

import com.vic.mvc.framework.orm.load.EntityLoad;
import com.vic.mvc.framework.util.PrintUtil;

@WebListener("容器的监听器 会加载此测试框架的所有机制")
public class ContaiberVicListener implements ServletContextListener{


	@Override
	public void contextInitialized(ServletContextEvent sce) {
		PrintUtil.print("加载监听器");
		EntityLoad.init();
		
		addServletMapping(sce.getServletContext());
		
		
	}
	
	@Override
	public void contextDestroyed(ServletContextEvent context) {
	}
	
	private void addServletMapping(ServletContext context) {
        // 用 DefaultServlet 映射所有静态资源
        ServletRegistration defaultServletRegistration = context.getServletRegistration("default");
        defaultServletRegistration.addMapping("/WEB-INF/*");
        // 用 JspServlet 映射所有 JSP 请求
        ServletRegistration jspServletRegistration = context.getServletRegistration("jsp");
        jspServletRegistration.addMapping("/dynamic/jsp/*");
        // 用 UploadServlet 映射 /upload.do 请求
        ServletRegistration uploadServletRegistration = context.getServletRegistration("upload");
        uploadServletRegistration.addMapping("/upload.do");
        
    }

}
